/**
* 订单管理 交易订单
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>即开收入列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="开始日期-结束日期">
        <el-date-picker v-model="startAndEndvalue" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="即开类型">
        <el-select :multiple="false" v-model="param.typeName" placeholder="请选择即开类型" style="width:150px;">
          <el-option v-for="item in typeList" :key="item.name" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label='店铺列表'>
        <el-select :multiple="false" v-model="param.stationId" placeholder="请选择店铺" style="width:150px;">
          <el-option v-for="item in stationLst" :key="item.id" :label="item.station_name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="getIntegralList(1)">搜索</el-button>
      </el-form-item>

    </el-form>
    <el-form>
      <el-form-item label="汇总金额">
        <el-button size="small" type="primary">{{ sumMoney }}</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
      element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column prop="id" label="id" width="60">
      </el-table-column>

      <el-table-column prop="stationEntity" label="店铺主图" width="120">

        <template slot-scope="scope">
          <img style="width: 90px;height: 90px;" :src="scope.row.stationEntity.station_image">
        </template>

      </el-table-column>
      <el-table-column sortable prop="stationEntity" label="店铺名称" width="100">
        <template slot-scope="scope">
          {{ scope.row.stationEntity.station_name }}
        </template>
      </el-table-column>


      <el-table-column prop="typeName" label="即开类型" width="100">
      </el-table-column>

      <el-table-column prop="money" label="金额" width="140" show-overflow-tooltip>

      </el-table-column>

      <el-table-column prop="remark" label="备注" width="100">
      </el-table-column>

      <el-table-column prop="addTime" label="创建时间" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ transformDate(scope.row.createTime) }}</div>
        </template>
      </el-table-column>

    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
  </div>
</template>

<script>
import { getBackstageRecordList, getInstantTakeTypeList, getStationList } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览',

      userKey: "",
      status: 0,
      formInline: {
        page: 1,
        limit: 10,
        machineNo: '',
        orderNo: '',
        transId: '',
        payType: 0,
        orderStatus: 0,
        token: localStorage.getItem('logintoken')
      },

      listData: [], //用户数据
      pageparm: {
        currentPage: 1,
        pageSize: 20,
        total: 10
      },
      sumMoney: '31231',


      startAndEndvalue: '',
      param: {
        typeName: "",
        stationId: '',
      },
      typeList: [],
      stationLst: [],
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getIntegralList(1)
    this.getTakeTypeLst()
    this.getStationLst()

  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    getStationLst() {
      getStationList({ type: 0 }).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.stationLst = res.data.list;
          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      });
    },
    getTakeTypeLst() {
      getInstantTakeTypeList({
        page: 0,
      }).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.typeList = res.data.list;
          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      })
    },
    getMainImg(goodsData) {

      return JSON.parse(JSON.parse(goodsData).carousel)[0];

    },
    // 获取订单列表
    getIntegralList(page) {
      console.log(' this.param====>', this.param)
      console.log(' this.startAndEndvalue====>', this.startAndEndvalue)
      let beginTime = -1
      let endTime = -1
      if (this.startAndEndvalue.length > 0) {
        beginTime = this.startAndEndvalue[0].getTime() / 1000
        endTime = this.startAndEndvalue[1].getTime() / 1000
      }
      this.loading = true;
      var parameter = {
        typeName: this.param.typeName,
        beginTime,
        endTime,
        stationId: this.param.stationId || -1,
        page: (page - 1) * 20,
      }
      getBackstageRecordList(parameter).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.listData = res.data.list;
          this.pageparm.currentPage = page;
          this.pageparm.total = res.data.count;
          this.sumMoney = res.data.sumMoney
          console.log('res=getBackstageRecordList=====>', sumMoney)

          var fileList = []

          for (let index = 0; index < this.listData.length; index++) {
            const element = this.listData[index];

            var statusName = "";

            if (element.status == 0) {
              statusName = "支出"
            }
            if (element.status == 1) {
              statusName = "收入"
            }



            var creation_time = this.transformDate(element.creation_time);



            var item = {
              id: element.id,//id
              mobile: element.userEntity.mobile,//用户手机号
              number: element.number,//积分数量
              title: element.title,//备注
              status: statusName,//状态
              creation_time: creation_time,//创建时间

            }


            fileList.push(item)



          }

          this.fileList = fileList;






          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      });
    },

    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getIntegralList(this.formInline.page)
    },

    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true
      this.orderInfo = row;
      this.getOrderDetails()
    },


    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>